using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace CDTM.Modules.DANHMUC.Components
{
    public partial class DM
    {

        //---------------------------------------------------------------------------------------------

        public static List<DM> SelectCollectionBy(Guid moduleID, int categoryID)
        {
            List<DM> collection = new List<DM>();
            SqlDataReader reader = (SqlDataReader)SelectReaderAll(moduleID, categoryID);
            while (reader.Read())
            {
                DM entity = new DM();

                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Name"))) entity.Name = reader.GetString(reader.GetOrdinal("Name"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("SortOrder"))) entity.SortOrder = reader.GetInt32(reader.GetOrdinal("SortOrder"));
                if (!reader.IsDBNull(reader.GetOrdinal("TrangThai"))) entity.TrangThai = reader.GetBoolean(reader.GetOrdinal("TrangThai"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CategoryID"))) entity.CategoryID = reader.GetInt32(reader.GetOrdinal("CategoryID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedByUser"))) entity.CreatedByUser = reader.GetString(reader.GetOrdinal("CreatedByUser"));
                if (!reader.IsDBNull(reader.GetOrdinal("DateCreated"))) entity.DateCreated = reader.GetDateTime(reader.GetOrdinal("DateCreated"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModifiedByUser"))) entity.ModifiedByUser = reader.GetString(reader.GetOrdinal("ModifiedByUser"));
                if (!reader.IsDBNull(reader.GetOrdinal("DateModified"))) entity.DateModified = reader.GetDateTime(reader.GetOrdinal("DateModified"));
                collection.Add(entity);
            }

            reader.Close();
            return collection;
        }

        //---------------------------------------------------------------------------------------------

        public static IDataReader SelectReaderAll(Guid moduleID, int categoryID)
        {
            return SelectReaderDynamic("ModuleID = '{" + moduleID + "}' AND CategoryID = " + categoryID, "");
        }
    }
}